<template>
  <div style="width: 100%; height: 100%">
    <div id="chart-bar" ref="chart-bar"></div>
  </div>
</template>

<script>
import * as echarts from "echarts/lib/echarts";
import { BarChart } from "echarts/charts";
import {
  TooltipComponent,
  LegendComponent,
  GridComponent,
  DataZoomComponent,
  TitleComponent,
  GraphicComponent,
} from "echarts/components";
echarts.use([
  BarChart,
  GridComponent,
  TooltipComponent,
  LegendComponent,
  DataZoomComponent,
  TitleComponent,
  GraphicComponent,
]);
import resize from "@/mixins/resize.js";
export default {
  mixins: [resize],
  data() {
    return {
      chart: null,
    };
  },
  created() {
    this.$nextTick(() => {
      this.chart = echarts.init(this.$refs["chart-bar"]);
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart.setOption({
        xAxis: {
          type: "category",
          data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            data: [120, 200, 150, 80, 70, 110, 130],
            type: "bar",
          },
        ],
      });
    },
  },
};
</script>
<style scoped>
#chart-bar {
  width: 100%;
  height: 100%;
}
</style>